<!-- 公共文件 start -->
@extends('admin.public.base')
<!-- 公共文件 end -->

@section('content')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item" style="text-align:center;font-size:18px;">
                    <b>出库订单号：{{$data['order_sn']}}</b>
                    <div class="icon iconfont" style="float:right;">&#xe6c9;</div>
                </div>
                <hr>
                <div class="layui-form-item">
                    <label class="layui-form-label"><b>商品信息：</b></label>
                    <div class="layui-input-block" style="line-height:36px">
                        <img src="{{$goods['goods_img']}}" width="100px"><br>
                        商品名称：{{$goods['goods_name']}}<br>
                        商品编号：{{$goods['goods_sn']}}<br>
                        商品分类：{{$goods['cate_name']}}<br>
                        商品单价：{{$goods['goods_price']}}元<br>
                        商品售价：<b class="myMoney">{{$goods['goods_price']}}</b>元<br>
                        商品可售库存：{{$goods['goods_sale_num']}}/{{$goods['goods_unit']}}<br>
                        商品总库存：{{$goods['goods_total_num']}}/{{$goods['goods_unit']}}<br>
                    </div>
                </div>

                <!-- 新增生产批次日期字段 -->
{{--                <div class="layui-form-item">--}}
{{--                    <label class="layui-form-label"><span class="x-red">*</span>生产批次日期</label>--}}
{{--                    <div class="layui-input-inline">--}}
{{--                        <input type="text" name="store_product_batch" id="store_product_batch"--}}
{{--                               class="layui-input" placeholder="格式：YYYY-MM-DD" lay-verify="required|dateFormat" lay-reqtext="请选择生产批次日期" value="{{ !empty($goods['first_store_product_batch']) ? $goods['first_store_product_batch'] : date('Y-m-d') }}">--}}
{{--                    </div>--}}
{{--                </div>--}}

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="x-red">*</span>入库数量</label>
                        <div class="layui-input-inline">
                            <input type="text" name="goods[{{$goods['id']}}][goods_number]" lay-verify="required"
                                   lay-reqtext="必填项,请填写信息"
                                   class="layui-input" value="1" onBlur="sumGoodsPrice()" id="mySaleNum">
                            <input type="hidden" name="goods[{{$goods['id']}}][goods_id]" value="{{$goods['id']}}">
                            <input type="hidden" name="goods[{{$goods['id']}}][goods_price]"
                                   value="{{$goods['goods_price']}}" id="mySalePrice">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-block">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" class="layui-textarea"
                                      name="remark">{{ $data['remark'] }}</textarea>
                        </div>
                    </div>
                </div>
                <hr>
                <div class="layui-form-item">
                    <label class="layui-form-label"><b>资金信息：</b></label>
                    <div class="layui-input-block" style="line-height:36px">
                        总数量：<b class="zNum">1</b>个<br>
                        总金额：<b class="zMoney">{{$goods['goods_price']}}</b>元<br>
                    </div>
                </div>
                <hr>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <input type="hidden" value="{{$data['order_sn']}}" name="order_sn">
                    <button class="layui-btn" lay-filter="add" lay-submit="">提交</button>
                </div>
            </form>
        </div>
    </div>

    <script type="text/javascript" src="/static/admin/js/xcity.js"></script>
    <script>
        // 计算价格
        function sumGoodsPrice() {
            var totalNum = 0;
            var money = 0;
            totalNum = $("#mySaleNum").val();
            money = $("#mySaleNum").val() * $("#mySalePrice").val();
            $(".zMoney").html(money);
            $(".zNum").html(totalNum);
        }

        layui.use(['form', 'layer', 'jquery', 'code'], function () {
            $ = layui.jquery;
            form = layui.form;

            // 自定义日期格式校验
            form.verify({
                dateFormat: function(value){
                    var reg = /^\d{4}-\d{2}-\d{2}$/;
                    if(!reg.test(value)){
                        return '日期格式必须为YYYY-MM-DD';
                    }
                }
            });

            //监听提交
            form.on('submit(add)', function (data) {
                if (confirm("你确定生成入库单吗？")) {
                    $.ajax({
                        type: 'POST',
                        url: '/admin/stock/enterOrderAdd',
                        data: data.field,
                        dataType: 'json',
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                        },
                        success: function (data) {
                            layer.alert(data.msg);
                            if (data.code == 1) {
                                xadmin.close();
                                xadmin.father_reload();
                            }
                        },
                        error: function (xhr, type) {
                            alert('Ajax error!');
                        }
                    });
                }
                return false;
            });

        });

        //HTML反转义
        function HTMLDecode(text) {
            var temp = document.createElement("div");
            temp.innerHTML = text;
            var output = temp.innerText || temp.textContent;
            temp = null;
            return output;
        }
    </script>
@endsection
